;SLIDE Misc Library 

 INCLUDE "libraries.inc"

 CreateLibrary Misc,Delay,LoadKey,IfKey,WaitKey,LoadWaitKey,PauseForKey,IfNKey,LoadWaitTIOSKey,IfAnyKey


 IFDEF __LoadWaitTIOSKey
_LoadWaitTIOSKey_:
       B_CALL LdHLInd
       push   hl
LoadWaitTIOSKeyLoop:
       B_CALL GetKey
       jr     z,LoadWaitTIOSKeyLoop
       ld     l,a
       ld     h,0
       pop    de
       jp     LoadToVar
 ENDIF

 IFDEF __IfNKey
 IFNDEF __MiscKeyThing
 DEFINE __MiscKeyThing
 ENDIF
_IfNKey_:
       call   MiscKeyThing
       ret    nz
       jp     SkipNextCmdRet
 ENDIF

 IFDEF __IfKey
 IFNDEF __MiscKeyThing
 DEFINE __MiscKeyThing
 ENDIF
_IfKey_:
       call   MiscKeyThing
       ret    z
       jp     SkipNextCmdRet
 ENDIF

 IFDEF __IfAnyKey
_IfAnyKey_:
       B_CALL GetCSC
       or     a
       ret    nz
       jp     SkipNextCmdRet
 ENDIF


 IFDEF __MiscKeyThing
MiscKeyThing:
       ld     a,(hl)
       call   ConvVal8Bit
       ld     b,a
       B_CALL GetCSC
       cp     b
       ret
 ENDIF

 IFDEF __PauseForKey
 IFNDEF __WaitKey
 DEFINE __WaitKey
 ENDIF
_PauseForKey_:
       ld     a,(hl)
       call   ConvVal8Bit
       ld     b,a
PauseForKeyLoop:
       call   _WaitKey_
       cp     b
       jr     nz,PauseForKeyLoop
       ret
 ENDIF

 IFDEF __WaitKey
_WaitKey_:
       ei
WaitKeyLoop:
       halt
       B_CALL GetCSC
       or     a
       jr     z,WaitKeyLoop
       ret
 ENDIF

 IFDEF __LoadWaitKey
_LoadWaitKey_:
       B_CALL LdHLInd
       push   hl
       ei
LoadWaitKeyLoop:
       halt
       B_CALL GetCSC
       or     a
       jr     z,LoadWaitKeyLoop
       ld     l,a
       ld     h,0
       pop    de
       jp     LoadToVar
 ENDIF


 IFDEF __LoadKey
_LoadKey_:
       B_CALL LdHLInd
       ex     de,hl
       B_CALL GetCSC
       ld     l,a
       ld     h,0
       jp     LoadToVar
       
 ENDIF


 IFDEF __Delay
_Delay_:
       call   LdHLIndConvVal
       ei
DelayLoop:
       halt
       dec    hl
       ld     a,h
       or     l
       jr     nz,DelayLoop
       ret
 ENDIF
MiscNext:
 IFDEF _S_Delay
       db     4
 ENDIF
 IFDEF _S_LoadKey
       db     4
 ENDIF
 IFDEF _S_IfKey
       db     3
 ENDIF
 IFDEF _S_WaitKey
       db     2
 ENDIF
 IFDEF _S_LoadWaitKey
       db     4
 ENDIF
 IFDEF _S_PauseForKey
       db     3
 ENDIF
 IFDEF  _S_IfNKey
       db     3
 ENDIF
 IFDEF _S_LoadWaitTIOSKey
       db     4
 ENDIF
 IFDEF _S_IfAnyKey
       db     2
 ENDIF
